<!DOCTYPE html>
<html>
<head>
    <title>Perturbation Theory Potential Well</title>
</head>
<body>
<canvas id="physicsCanvas" width="600" height="450"></canvas>
<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // --- Style and Configuration ---
    const cx = canvas.width / 2;
    const cy = canvas.height / 1.7; // Position the horizontal axis lower on the canvas
    const a = 60; // Scale factor for 'a' in pixels
    const v0Height = 80; // Height of the V0 potential in pixels
    const wallHeight = 200; // Height of the infinite walls

    ctx.lineWidth = 2;
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';

    // --- Draw Title ---
    ctx.textAlign = 'center';
    ctx.font = "italic 28px 'Times New Roman', serif";
    ctx.fillText("Perturbation Theory", cx, 40);

    // --- Draw Potential Well ---
    ctx.beginPath();
    // Left infinite wall
    ctx.moveTo(cx - 3 * a, cy - wallHeight);
    ctx.lineTo(cx - 3 * a, cy);
    // Bottom left segment
    ctx.lineTo(cx - a, cy);
    // Left side of V0 bump
    ctx.lineTo(cx - a, cy - v0Height);
    // Top of V0 bump
    ctx.lineTo(cx + a, cy - v0Height);
    // Right side of V0 bump
    ctx.lineTo(cx + a, cy);
    // Bottom right segment
    ctx.lineTo(cx + 3 * a, cy);
    // Right infinite wall
    ctx.lineTo(cx + 3 * a, cy - wallHeight);
    ctx.stroke();

    // --- Draw Labels ---

    // Y-axis label 'V'
    ctx.font = "italic bold 24px 'Times New Roman', serif";
    ctx.textAlign = 'right';
    ctx.textBaseline = 'middle';
    ctx.fillText("V", cx - 3 * a - 15, cy - wallHeight + 40);

    // X-axis position labels
    ctx.font = "italic 20px 'Times New Roman', serif";
    ctx.textAlign = 'center';
    ctx.textBaseline = 'top';
    const labelY = cy + 10;
    ctx.fillText("-3a", cx - 3 * a, labelY);
    ctx.fillText("-a", cx - a, labelY);
    ctx.fillText("a", cx + a, labelY);
    ctx.fillText("3a", cx + 3 * a, labelY);

    // --- Draw V0 Label and Indicator ---
    // Position the indicator line inside the [-a, a] region, on the left side
    const v0IndicatorX = cx - 0.6 * a;
    ctx.beginPath();
    // Vertical line
    ctx.moveTo(v0IndicatorX, cy);
    ctx.lineTo(v0IndicatorX, cy - v0Height);
    // Top tick
    ctx.moveTo(v0IndicatorX - 8, cy - v0Height);
    ctx.lineTo(v0IndicatorX + 8, cy - v0Height);
    // Bottom tick
    ctx.moveTo(v0IndicatorX - 8, cy);
    ctx.lineTo(v0IndicatorX + 8, cy);
    ctx.stroke();

    // V0 text
    ctx.font = "italic bold 22px 'Times New Roman', serif";
    ctx.textAlign = 'right';
    ctx.textBaseline = 'middle';
    ctx.fillText("V", v0IndicatorX - 15, cy - v0Height / 2);
    // Subscript '0'
    ctx.font = "bold 16px 'Times New Roman', serif";
    ctx.fillText("0", v0IndicatorX - 15 + 8, cy - v0Height / 2 + 8);

    // --- Draw Caption ---
    ctx.font = "20px 'Times New Roman', serif";
    ctx.textAlign = 'center';
    ctx.textBaseline = 'bottom';
    ctx.fillText("Fig. 5.4", cx, canvas.height - 20);
</script>
</body>
</html>